
// Get the path of the currently running do-file
local do_file_path `c(pwd)'

// Change the working directory to the location of the do-file
cd "`do_file_path'"

clear

*use "!proc_data\ROADLENGTH_2021-01-13.dta"
use "proc_data\ROADLENGTH_2021-02-25.dta"

rename *, lower
drop country gid_0 

collapse (sum) len_m, by(objectid r2014-r1965)

sort objectid 

tabulate r2014, generate(roadm2014)
tabulate r2008, generate(roadm2008)
tabulate r2003, generate(roadm2003)
tabulate r1998, generate(roadm1998)
tabulate r1996, generate(roadm1996)
tabulate r1993, generate(roadm1993)
tabulate r1991, generate(roadm1991)
tabulate r1990, generate(roadm1990)
tabulate r1988, generate(roadm1988)
tabulate r1986, generate(roadm1986)
tabulate r1985, generate(roadm1985)
tabulate r1984, generate(roadm1984)
tabulate r1983, generate(roadm1983)
tabulate r1976, generate(roadm1976)
tabulate r1973, generate(roadm1973)
tabulate r1971, generate(roadm1971)
tabulate r1969, generate(roadm1969)
tabulate r1968, generate(roadm1968)
tabulate r1967, generate(roadm1967)
tabulate r1965, generate(roadm1965)

drop r2014-r1965

*g var=1
reshape long roadm, i(objectid len_m) j(year) string
replace roadm = roadm * len_m
drop if roadm==0

g rdcat = substr(year, 5, 1)
replace year = substr(year,1,4)
destring year, replace

destring rdcat, replace
* replace categorical numbers in place of ordered index
replace rdcat=8 if rdcat==5
replace rdcat=5 if rdcat==4
replace rdcat=0 if rdcat==1
replace rdcat=1 if rdcat==2
replace rdcat=3 if rdcat==3

label define roadlabel 0 "Earthen : 0" 1 "paved : 1" 3 "Improved : 3" 5 "Earthen : 5" 8 "Highway (2x3 lanes): 8"
label values rdcat roadlabel
label variable roadm "Road length (meters)"
label variable year "Digitized published year : michelin maps"
label variable rdcat "Road category from michelin maps"

drop len_m

save "proc_data\ROADTYPEM_ts02262021.dta", replace